package health_system.health_system.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
@Entity
@Table(name = "moments")
public class Moment extends BaseEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;
    
    @Size(max = 1000)
    @Column(columnDefinition = "TEXT")
    private String content;
    
    @OneToMany(mappedBy = "moment", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    private Set<MomentMedia> mediaList = new HashSet<>();
    
    @OneToMany(mappedBy = "moment", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<MomentLike> likes = new HashSet<>();
    
    @OneToMany(mappedBy = "moment", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<MomentComment> comments = new HashSet<>();
    
    @OneToMany(mappedBy = "originalMoment", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<MomentShare> shares = new HashSet<>();
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private VisibilityType visibility = VisibilityType.FRIENDS;
    
    @Column(nullable = false)
    private Integer visibilityDuration = 0; // 0 means forever, 3, 30, 180 for days
    
    @ManyToMany
    @JoinTable(
        name = "moment_visibility_users",
        joinColumns = @JoinColumn(name = "moment_id"),
        inverseJoinColumns = @JoinColumn(name = "user_id")
    )
    private Set<User> visibleToUsers = new HashSet<>();
    
    public enum VisibilityType {
        PUBLIC, FRIENDS, PRIVATE, CUSTOM
    }
} 